package Metier;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import Mappages.CL_mp_lieu;
import Mappages.CL_mp_poi;

public class CL_poi {
	private ResultSet rs ;
	private int id;
	private String libelle;
	private int coordonnee_Y;
	private int coordonnee_X;
	private String description;
	private String lien;
	private String image;
	private CL_mp_poi omppoi;
	private int ID_POI; 
	private List<CL_poi> AllPoi = new ArrayList<CL_poi>();
	
	CL_mp_lieu olieu = new CL_mp_lieu();	
	CL_mp_poi opoi = new CL_mp_poi();
	
	//Constructeur
	public CL_poi () {
	}

	public CL_poi (int id, String libelle, int coordonnee_Y, int coordonnee_X, String description, String lien, String image)
	{
		setId (id);
		setLibelle (libelle);
		setCoordonnee_Y (coordonnee_Y);
		setCoordonnee_X (coordonnee_X);
		setDescription (description);
		setLien (lien);
		setImage (image);
	}
	
	//Assesseur SET
	public void setId(int id) {
		this.id = id;
	}
	
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
	
	public void setCoordonnee_Y(int coordonnee_Y) {
		this.coordonnee_Y = coordonnee_Y;
	}
	
	public void setCoordonnee_X(int coordonnee_X) {
		this.coordonnee_X = coordonnee_X;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public void setLien(String lien) {
		this.lien = lien;
	}
	
	public void setImage(String image) {
		this.image = image;
	}
	
	//Assesseur SET
	
	public int getId() {
		return this.id;
	}

	public String getLibelle() {
		return this.libelle;
	}


	public int getCoordonnee_Y() {
		return this.coordonnee_Y;
	}

	public int getCoordonnee_X() {
		return this.coordonnee_X;
	}

	public String getDescription() {
		return this.description;
	}

	public String getLien() {
		return this.lien;
	}

	public String getImage() {
		return this.image;
	}

	//Methode
	public void M_recup_modif_poi (int id_poi, String libelle, double X, double Y, String description, String lien, String image){
		
	}

	public void M_recup_modif_poi (String libelle, double X, double Y, String description, String lien, String image){

		
	}
	
	public int M_select_id_POI (String nom){
		
		omppoi = new CL_mp_poi();
		ID_POI = omppoi.M_recuperer_ID_poi(nom);
		return ID_POI;
	}

	public void M_recup_ajouter_poi (String libelle, double X, double Y, String description, String lien, String image)
	{		
		omppoi = new CL_mp_poi();
		//La methode suivante retourne l'id du nouvel enregistrement;
		omppoi.M_ajouter_poi(libelle, X, Y, description, lien, image);		
	}
	
	public void M_recup_supprimer_poi (int id_poi){
		omppoi = new CL_mp_poi();
		omppoi.M_supprimer_poi(id_poi);
	}
	
	public void M_recup_select_poi_textbox () throws SQLException{
		       
}

	public List<CL_poi> ListAllPoi() throws SQLException {

	

		this.rs = this.omppoi.M_select_poi();
		while(rs.next()) {
			CL_poi Olist = new CL_poi(rs.getInt("ID_POI"), rs.getString("LIBELLE"),rs.getInt("coordonnee_Y"), rs.getInt("coordonnee_X"), rs.getString("description"),rs.getString("lien"),rs.getString("image") );
			AllPoi.add(Olist);
		}
		return AllPoi;
	}

	public String[] m_charger_pois(String poi, String lieu, String pays)
 {
		int a = 0;
		int taille = 0;
		omppoi = new CL_mp_poi();
		rs = omppoi.m_select_poi(poi, lieu, pays);
		try {
			rs.last();
			taille = rs.getRow();
			rs.beforeFirst();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}

		
		try {
			
			if(taille != 0){
				String[] data = new String[taille];	
				while(rs.next())
				{
					data[a] = (rs.getString("LIBELLE"));
					a++;
				}
				return data;	
			}
		else{
			String[]data = new String[1];
			data[0]="pas de poi pour ce lieu";
			return data;			
		}
			} 
			catch (SQLException e) {
				
				e.printStackTrace();
			}
		return null;
	}
	

	public List<CL_poi> m_traitement_afficher_poi(String ville, String pays)	
	{
		

		rs = opoi.m_select_poi("", ville, pays);

		
			try 
			{
				if(rs != null)
				{
					
					while(rs.next()) 
					{
					CL_poi liste = new CL_poi(rs.getInt("ID_POI"), rs.getString("LIBELLE"),rs.getInt("coordonnee_Y"), rs.getInt("coordonnee_X"), rs.getString("description"),rs.getString("lien"),rs.getString("image") );
					AllPoi.add(liste);
			System.out.println("X : "+liste.getCoordonnee_X());
			System.out.println("Y : "+liste.getCoordonnee_Y());
					}
					return AllPoi;
				}
				else
				{
					return null;
				}
			}
							
			
			catch (SQLException e) 
			{
				throw new RuntimeException("marche po");
			}
			
		}

		
	

	}

